<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
<!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--        <a-row :gutter="24">-->
<!--          <a-col :md="5" :sm="12">-->
<!--            <a-form-model-item label="年级" prop="gradeId">-->
<!--              <j-dict-select-tag v-model="queryParam.gradeId" @change='changeClassId' placeholder="请选择所属年级" dictCode="cou_grade,grade_name,id"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->

<!--          <a-col :md="5" :sm="12">-->
<!--            <a-form-model-item label="班级" prop="classId">-->
<!--              <j-dict-select-tag v-model="queryParam.targetObjId" placeholder="请选择所属班级" :dictCode="dictSelectParams.classId"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->

<!--          <a-col :md="4" :sm="8">-->
<!--            <a-form-model-item label="课表状态" prop="courseArrangeStatus">-->
<!--              <j-dict-select-tag type="list"  v-model="queryParam.courseArrangeStatus" placeholder="选择课表状态" dictCode="course_arrange_status"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <template v-if="toggleSearchStatus">-->
<!--            <a-col :md="4" :sm="8">-->
<!--              <a-form-model-item label="启用状态">-->
<!--                <j-dict-select-tag type="list" v-model="queryParam.izOpen"-->
<!--                                   dictCode="iz_open" placeholder="选择是否启用状态" />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--          </template>-->
<!--          <a-col :md="6" :sm="8">-->
<!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
<!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
<!--              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
<!--            </span>-->
<!--          </a-col>-->
<!--        </a-row>-->
<!--      </a-form>-->

      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col >
            <a-form-model-item label="年级" prop="gradeId">
              <s-multi-select-tag  type='checkbox'v-model="queryParam.gradeId" @change='changeGradeId' placeholder="请选择所属年级" dictCode="cou_grade,grade_name,id"
                                   :is-pin-yin="false"/>
            </a-form-model-item>
          </a-col>
        </a-row>

          <a-row style='height: 100px'>
            <a-col  >
              <a-form-model-item label="班级" prop="classId" >
                <s-multi-select-tag   type='checkbox' v-model="queryParam.targetObjId" placeholder="请选择所属班级" :dictCode="queryParamSelect.classIdSelect" :is-pin-yin="false"/>
              </a-form-model-item>
            </a-col>
          </a-row>




        <template v-if="toggleSearchStatus">
          <a-row >
            <a-col :md="14" :sm="8">
              <a-form-model-item label="课表状态" prop="courseArrangeStatus">
                <s-dict-select-tag type="radioButtonNew"  v-model="queryParam.courseArrangeStatus" placeholder="选择课表状态" dictCode="course_arrange_status"/>
              </a-form-model-item>
            </a-col>
            <a-col :md="4" :sm="8">
              <a-form-model-item label="是否启用">
                <s-dict-select-tag type="radioButtonNew" v-model="queryParam.izOpen"
                                   dictCode="iz_open" placeholder="选择是否启用状态" />
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-model-item label="忽略">
                <j-checkbox
                  v-model="queryParam.ignorePropertyList"
                  :options="queryParamSelect.ignorePropertyList"
                />
              </a-form-model-item>
            </a-col>
<!--            <a-col :md="12" :sm="8">-->
<!--              <a-form-model-item label="包含">-->
<!--                <j-checkbox-->
<!--                  v-model="queryParam.includePropertyList"-->
<!--                  :options="queryParamSelect.includePropertyList"-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
          </a-row>
        </template>
        <a-row style='margin-top: 5px'>
          <a-col :offset='8'>
            <span>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>

      </a-form>

    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('cou_course_arrange')">导出</a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import'>导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList='superFieldList' ref='superQueryModal'
                     @handleSuperQuery='handleSuperQuery'></j-super-query>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='initCourseArrangeAtom'><a-icon type='sync' />初始化课表</a-menu-item>
          <a-menu-item key='1' @click='refashArrangeAtomTeacher'><a-icon type='sync' />刷新任课老师</a-menu-item>
          <a-menu-item key='1' @click='refashArrangeAtomClassroom'><a-icon type='sync' />刷新教室</a-menu-item>
          <a-menu-item key='1' @click='delInitCourseArrangeAtom'><a-icon type='delete' />删除重新初始化</a-menu-item>
          <a-menu-item key='1' @click='batchizOpen1'><a-icon type='sync' />启用</a-menu-item>
          <a-menu-item key='1' @click='batchizOpen0'><a-icon type='delete' />停用</a-menu-item>
          <a-menu-item key='1' @click='batchDel'><a-icon type='delete' />删除</a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>

      <!-- 是否发布开关 -->
      <template>
        <span><a-button type='primary' style='margin-left: 20px;background-color: #e50a36;border: none;'
                        @click='handleReleaseOk(4)'>批量发布</a-button></span>
        <span><a-button type='primary' style='margin-left: 20px;border: none;'
                        @click='copyCourseArrange()'>复制课表</a-button></span>
        <!--        <div>-->
        <!--          <a-modal v-model:visible='courseReleaseVisible' title='课表发布' @ok='handleReleaseOk'>-->
        <!--            <template #footer>-->
        <!--              <a-button key='back' @click='handleReleaseCancel'>取消</a-button>-->
        <!--              <a-button key='submit' type='primary' :loading='loading' @click='handleReleaseOk'>提交操作</a-button>-->
        <!--            </template>-->
        <!--            <a-form-model-item label='课表发布状态' prop='courseArrangeStatus' style='width: 82%'>-->
        <!--              <j-dict-select-tag v-model='courseReleaseStatu' type='list' dictCode='course_arrange_status,'-->
        <!--                                 style='width: 80%' placeholder='课表状态：(3已排课 4已发布 5已下线 6需重排)' />-->
        <!--            </a-form-model-item>-->
        <!--          </a-modal>-->
        <!--        </div>-->
      </template>
      <!-- 复制课表 -->
      <div>
        <a-modal width='35%' v-model:visible='copyCourseArrangeVisible' title='复制课表' @ok='copyCourseArrangeOk'>
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="课表名称" prop="courseArrangeName">
                <a-input v-model="copyCourseArrangeModel.courseArrangeName" placeholder="请输入课表名称"  style='width: 98%'></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="所属学年" prop="schoolYearId">
                <a-select v-model="copyCourseArrangeModel.schoolYearId" placeholder="请选择学年"  style='width: 97%'
                          :getPopupContainer="(target) => target.parentNode">
                  <a-select-option v-for="item in schoolYearDataList" :key="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="所属学期" prop="semesterId">
                <a-select v-model="copyCourseArrangeModel.semesterId" placeholder="请输入学期" style='width: 97%'
                          :getPopupContainer="(target) => target.parentNode">
                  <a-select-option v-for="item in semesterDataList" :key="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="所属年级" prop="gradeId">
                <j-dict-select-tag type="list" v-model="copyCourseArrangeModel.gradeId" @change='selectChangeGradeId'  style='width: 97%' dictCode="cou_grade,grade_name,id"
                                   placeholder="选择所属年级" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="课表应用班级[必选]" prop="targetObjId">
<!--                <a-select v-model="copyCourseArrangeModel.targetObjId" placeholder="请输入课表应用班级" style='width: 97%'-->
<!--                          :getPopupContainer="(target) => target.parentNode">-->
<!--                  <a-select-option v-for="item in objectList" :key="item.value">{{ item.label }}</a-select-option>-->
<!--                </a-select>-->
                <j-dict-select-tag type="list" v-model="copyCourseArrangeModel.targetObjId"  style='width: 97%' :dictCode="copyCourseArrangeDictSelect.classIdSclect"
                                   placeholder="表示该课表应用对象（班级）" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <!-- 教室(0:不指定教室;1:指定教室) -->
              <a-radio-group v-model:value="copyClassroomIndex" name="radioGroup">
                <a-radio value="0">不指定教室</a-radio>
                <a-radio value="1">指定教室</a-radio>
              </a-radio-group>
            </a-col>
            <a-col :span="12" v-if='copyClassroomIndex === "1"'>
              <a-form-model-item label="所在教学楼" prop="buildingId">
                <j-dict-select-tag type="list" v-model="copyCourseArrangeModel.buildingId"  @change='selectChangeBuildingId'  style='width: 97%' dictCode="fac_building,building_name,id"
                                   placeholder="选择所在教学楼" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if='copyClassroomIndex === "1"'>
              <a-form-model-item label="班级教室[可选]" prop="classroomId">
                <j-dict-select-tag type="list" v-model="copyCourseArrangeModel.classroomId"  style='width: 97%' :dictCode="copyCourseArrangeDictSelect.classroomIdSclect"
                                   placeholder="选择班级教室[可选]" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="启用开始日期" prop="openStartTime">
                <j-date placeholder="请选择课表启用开始日期" v-model="copyCourseArrangeModel.openStartTime"  style="width: 97%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="启用结束日期(含)"  prop="openStopTime">
                <j-date placeholder="请选择课表启用结束日期(含)" v-model="copyCourseArrangeModel.openStopTime"  style="width: 97%" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <template #footer>
            <a-button key='back' @click='copyCourseArrangeCancel'>取消</a-button>
            <a-button key='submit' type='primary' :loading='loading' @click='copyCourseArrangeOk'>提交操作</a-button>
          </template>
        </a-modal>
      </div>
      <!-- 复制课表 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'
        :customRow='clickThenCheck'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='courseArrangeStatus_dictText' style='color: #00DB00' slot-scope='text'>
          <a-tag style='background-color: rgb(37,189,231);color: #ffffff;font-size: 14px;padding: 0px 10px 0px 10px;'>
            {{ text }}
          </a-tag>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
               <a-menu-item>
                <a @click='handleOld(record,6)'>撤回重排</a>
              </a-menu-item>
               <a-menu-item>
                <a @click='handleStop(record,5)'>下线</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <cou-course-arrange-modal ref='modalForm' @ok='modalFormOk'></cou-course-arrange-modal>


    <!--==== 下方区域  试卷项目数据显示 ==== -->
    <a-tabs defaultActiveKey='1'>
      <a-tab-pane tab='课表预览' key='1'>
        <PreviewCourseArrangeDetails ref='PreviewCourseArrangeDetails'></PreviewCourseArrangeDetails>
      </a-tab-pane>
      <a-tab-pane tab='冲突检测' key='2' forceRender>
        <CouCourseArrangeConflictDetection ref='CouCourseArrangeConflictDetection'></CouCourseArrangeConflictDetection>
      </a-tab-pane>
      <a-tab-pane tab='调课中心' key='3' forceRender>
        <CouCourseArrangeAdjustment ref='CouCourseArrangeAdjustment'></CouCourseArrangeAdjustment>
      </a-tab-pane>
    </a-tabs>
    <!--下方Table区域 操作按钮区域 -->

    <!--试卷新增 编辑Modal -->
    <!--    <ach-examination-paper-modal ref="modalForm" @ok="modalFormOk"></ach-examination-paper-modal>-->
    <!--    &lt;!&ndash;试卷项目新增 编辑Modal &ndash;&gt;-->
    <!--    <ach-exam-paper-project-item-modal ref="modalItemForm" @ok="modalItemFormOk"></ach-exam-paper-project-item-modal>-->
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CouCourseArrangeModal from './modules/CouCourseArrangeModal'
import { deleteAction, getAction, postAction, putAction } from '@api/manage'

import PreviewCourseArrangeDetails from '@views/smart_school/coursearrangePreview/PreviewCourseArrangeDetails'
import CouCourseArrangeConflictDetection from '@views/smart_school/coursearrangePreview/CouCourseArrangeConflictDetection'
import CouCourseArrangeAdjustment from '@views/smart_school/coursearrangePreview/CouCourseArrangeAdjustment'

import {
  getSchoolYearDataList, getSemesterDataList,
} from '@api/commonAPI'
import Template1 from '@views/jeecg/JVxeDemo/layout-demo/Template1'

export default {
  name: 'CouCourseArrangeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    Template1,
    CouCourseArrangeModal,
    PreviewCourseArrangeDetails,
    CouCourseArrangeConflictDetection,
    CouCourseArrangeAdjustment,
  },
  data() {
    return {
      description: 'cou_course_arrange管理页面',
      queryParam: {
        izOpen: "1",
        relObjTtype: '1,4,3',
        courArraAtomSectionHidden: "4,5,10",
        relObjIdHidden: ['7','8'], //隐藏的对象id，例如隐藏课间操和眼保健操
        budingId: null
      },
      //下拉查询
      queryParamSelect:{
        classIdSelect: null,
        classroomIdSelect: null,
        ignorePropertyList: [
          {label: '学年', value: '1'},
          {label: '学期', value: '2'},
          // {label: '部门', value: '3'},
          // {label: '届级', value: '4'}
        ],
        // includePropertyList:[{label: '按当前用户关联班级查班级课表', value: '1'},{label: '按当前老师查个人课表', value: '2'}],
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '班级',
          align: 'center',
          dataIndex: 'targetObjId_dictText'
        },
        {
          title: '课表编码',
          align: 'center',
          dataIndex: 'courseArrangeCode'
        },
        {
          title: '课表名称',
          align: 'center',
          dataIndex: 'courseArrangeName'
        },
        {
          title: '学期',
          align: 'center',
          dataIndex: 'semesterId_dictText'
        },
        {
          title: '学年',
          align: 'center',
          dataIndex: 'schoolYearId_dictText'
        },
        // {
        //   title: '课表类型',
        //   align: 'center',
        //   dataIndex: 'courseArrangeTtype_dictText'
        // },

        {
          title: '课表状态',
          align: 'center',
          dataIndex: 'courseArrangeStatus_dictText',
          scopedSlots: { customRender: 'courseArrangeStatus_dictText' }
        },
        {
          title: '启用开始日期',
          align: 'center',
          dataIndex: 'openStartTime',

          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '启用结束日期(含)',
          align: 'center',
          dataIndex: 'openStopTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '是否启用',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '是否删除',
          align: 'center',
          dataIndex: 'izDelete_dictText'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        // {
        //   title: '创建人',
        //   align: 'center',
        //   dataIndex: 'createUser'
        // },
        // {
        //   title:'编辑时间',
        //   align:"center",
        //   dataIndex: 'editTime',
        //   customRender:function (text) {
        //     return !text?"":(text.length>10?text.substr(0,10):text)
        //   }
        // },
        // {
        //   title:'编辑人',
        //   align:"center",
        //   dataIndex: 'editUser'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/coucoursearrange/couCourseArrange/listStatus',
        delete: '/coucoursearrange/couCourseArrange/delete',
        deleteBatch: '/coucoursearrange/couCourseArrange/deleteBatch',
        izOpen0Batch: '/coucoursearrange/couCourseArrange/izOpen0Batch',
        izOpen1Batch: '/coucoursearrange/couCourseArrange/izOpen1Batch',
        exportXlsUrl: '/coucoursearrange/couCourseArrange/exportXls',
        importExcelUrl: '/coucoursearrange/couCourseArrange/importExcel',
        //批量发布状态
        editBatch: '/coucoursearrange/couCourseArrange/editBatch',
        editBatchOldStop: '/coucoursearrange/couCourseArrange/editBatchOldStop',
        //复制课表
        copyCourseArrange: '/coucoursearrange/couCourseArrange/copyCourseArrange',
        //初始化课表
        initCourseArrangeAtom: '/coucoursearrange/couCourseArrange/initCourseArrangeAtom',
        //删除重新初始化课表
        delInitCourseArrangeAtom: '/coucoursearrange/couCourseArrange/delInitCourseArrangeAtom',
        //刷新任课老师
        refashArrangeAtomTeacher: '/coucoursearrange/couCourseArrange/refashArrangeAtomTeacher',
        //刷新教室
        refashArrangeAtomClassroom: '/coucoursearrange/couCourseArrange/refashArrangeAtomClassroom',
      },
      /* 排序参数 */
      isorter:{
        column: 'course_arrange_order',
        order: 'asc',
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '500', '1000'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      dictOptions: {},
      superFieldList: [],

      //发布
      courseReleaseVisible: false,
      courseReleaseStatu: '',
      //下拉查询
      dictSelectParams: {
        classId: "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 order by cc.grade_code !! cc.class_order !! cc.create_time",
      },

      //复制课表
      copyCourseArrangeVisible: false,
      copyCourseArrangeModel:{
        //下拉筛选
        gradeId: null,//筛选班级所属年级
        buildingId: null,//筛选教室所在教学楼
        //复制课表，特定属性自定义赋值
        id: null,//课表id
        courseArrangeName: null,//课表名称
        semesterId: null,//课表学期
        schoolYearId: null,//课表学年
        targetObjId: null,//课表班级
        classroomId: null,//班级教室
        openStartTime: null,//课表启用开始时间
        openStopTime: null,//课表启用结束时间
      },
      copyClassroomIndex: "0",//复制时，是否指定教室
      semesterDataList: [],
      schoolYearDataList: [],
      //联级变动
      copyCourseArrangeDictSelect: {
        classIdSclect: "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 order by cc.grade_code !! cc.class_order !! cc.create_time",
        classroomIdSclect: "fac_classroom fc,fc.classroom_name,fc.id,fc.classroom_iz_open  =1 order by fc.classroom_order !! fc.create_time",
      },

    }
  },
  created() {
    this.getSuperFieldList()
    this.getSchoolYearData();
    this.getSemesterData();
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'courseArrangeCode', text: '课表编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'courseArrangeName', text: '课表名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'semesterId', text: '学期', dictCode: '' })
      fieldList.push({ type: 'string', value: 'schoolYearId', text: '学年', dictCode: '' })
      fieldList.push({
        type: 'int',
        value: 'courseArrangeTtype',
        text: '课表类型(1:班级(默认);2教室场地 3.老师;4.科目 5:学生;)，课表应用对象类型',
        dictCode: ''
      })
      fieldList.push({
        type: 'string',
        value: 'targetObjId',
        text: '目标对象id(班级id(默认)，场地id，老师id，科目id,学生id)，表示该课表应用对象',
        dictCode: ''
      })
      fieldList.push({ type: 'int', value: 'courseArrangeIzSingle', text: '单双周标识(1单周（默认），2双周 3三周 4四周)', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'courseArrangeStatus',
        text: '课表状态：(1初始 2预排课 3已排课 4已发布 5已下线 6需重排)',
        dictCode: ''
      })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否启用（0否停用，1是启用）', dictCode: '' })
      fieldList.push({ type: 'date', value: 'openStartTime', text: '课表启用开始日期' })
      fieldList.push({ type: 'date', value: 'openStopTime', text: '课表启用结束日期(含)' })
      fieldList.push({ type: 'int', value: 'izDelete', text: '是否删除（0否 1是已删除）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校编码', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      fieldList.push({ type: 'string', value: 'createUser', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'editTime', text: '编辑时间' })
      fieldList.push({ type: 'string', value: 'editUser', text: '编辑人', dictCode: '' })
      this.superFieldList = fieldList
    },
    //查询change
    changeClassId(){
      this.dictSelectParams.classId = "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 and cc.grade_code = \'"+this.queryParam.gradeId+"\' order by cc.grade_code !! cc.class_order !! cc.create_time";
    },

    //发布
    showReleaseModal() {
      this.courseReleaseVisible = true
    },
    handleReleaseCancel() {
      this.courseReleaseVisible = false
    },
    //提交
    handleReleaseOk(val) {
      //===========状态修改（批量） start===========
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        let isReturn = false
        this.selectionRows.forEach(item => {
          if (item.courseArrangeStatus == 4) {
            this.$message.warning('课表选项中《' + item.courseArrangeName + '》是已发布数据，请重新选择！')
            isReturn = true
          }
        })
        if (isReturn) {
          return
        }
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        let params = {
          ids: ids,//多选id
          courseReleaseIndex: val//参数-修改的课表状态
        }
        var that = this

        this.$confirm({
          title: '提示-确认执行',
          content: (<div>
            <p>您确定要执行这个操作吗？</p>
            <p style='color:red;'>注意：重要操作，会生成相应的执行计划,如果是撤回重排后再次发布，前面生成的执行计划会丢失，请谨慎操作！</p>
          </div>),
          onOk() {
            that.loading = true
            putAction(that.url.editBatch, params).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.courseReleaseVisible = false
                that.loadData()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.loading = false
            })
          }
        })
      }
    },
    //撤回重排
    handleOld(val, sta) {
      //===========状态修改（批量） start===========
      if (val.courseArrangeStatus == 4) {
        let params = {
          id: val.id,//多选id
          courseReleaseIndex: sta//参数-修改的课表状态
        }
        var that = this
        this.$confirm({
          title: '提示-确认执行',
          content: (<div>
            <p>您确定要执行撤回操作吗？</p>
            <p style='color:red;'>注意：重要操作，撤回后再次发布，会对之前已经产生的执行计划进行覆盖，请谨慎操作！</p>
          </div>),
          onOk() {
            that.loading = true
            putAction(that.url.editBatchOldStop, params).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.loading = false
            })
          }
        })
      } else {
        this.$message.warning('课表没有发布，无法撤回')
      }
    },
    //下线
    handleStop(val, sta) {
      //===========状态修改（批量） start===========
      if (val.courseArrangeStatus == 4) {
        this.$message.warning('这条数据是已发布状态，不能进行下线操作，需要对该课表进行撤回后再进行下线！')
        return
      }
      let params = {
        id: val.id,//多选id
        courseReleaseIndex: sta//参数-修改的课表状态
      }
      var that = this
      this.$confirm({
        title: '提示-确认执行',
        content: (<div>
          <p>您确定要执行撤回操作吗？</p>
          <p style='color:red;'>注意：重要操作，撤回后再次发布，会对之前已经产生的执行计划进行覆盖，请谨慎操作！</p>
        </div>),
        onOk() {
          that.loading = true
          putAction(that.url.editBatchOldStop, params).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
              that.onClearSelected()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.loading = false
          })
        }
      })
    },

    clickThenCheck(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(','), [record])
          }
        }
      }
    },
    //上方触发
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;//多选多个id
      this.selectionRows = selectionRows;//多选多行完整数据
      //选中数据传递到调用页面
      this.$refs.PreviewCourseArrangeDetails.getOrderMain(this.selectionRows[0]); //课表预览页面 - selectionRows 暂时取第一个第一天数据，也可穿多个
      this.$refs.CouCourseArrangeConflictDetection.getOrderMain(this.selectionRows[0]);//冲突检测页面
      this.$refs.CouCourseArrangeAdjustment.getOrderMain(this.selectionRows[0]);//调课中心页面
    },

    //复制课表
    async getSchoolYearData() {
      let res = await getSchoolYearDataList()
      this.schoolYearDataList = []
      res.result.forEach(item => {
        this.schoolYearDataList.push({
          label: item.schoolYearName,
          value: item.id
        })
      })
    },
    async getSemesterData() {
      let res = await getSemesterDataList()
      this.semesterDataList = []
      res.result.forEach(item => {
        this.semesterDataList.push({
          label: item.semesterName,
          value: item.id
        })
      })
    },
    copyCourseArrange(){
      //判断是否选择了一项
      if (this.selectedRowKeys.length === 0){
        alert("请先选择一项你要复制的课表")
        return
      }
      if (this.selectedRowKeys.length > 1){
        alert("复制课表时，只能选择一条课表数据")
        return
      }
      this.copyCourseArrangeVisible = true
    },
    //复制取消
    copyCourseArrangeCancel(){
      this.copyCourseArrangeVisible = false
    },
    //复制课表 提交
    copyCourseArrangeOk(){
      if (this.copyCourseArrangeModel.courseArrangeName === null){
        alert("复制课表的名称不能为空")
        return
      }
      if (this.copyCourseArrangeModel.semesterId === null){
        alert("复制课表,必须指定学期")
        return
      }
      if (this.copyCourseArrangeModel.schoolYearId === null){
        alert("复制课表,必须指定学年")
        return
      }
      if (this.copyCourseArrangeModel.targetObjId === null){
        alert("复制课表,必须指定班级")
        return
      }
      if (this.copyCourseArrangeModel.openStartTime === null){
        alert("复制课表,必须指定启用开始时间")
        return
      }if (this.copyCourseArrangeModel.openStopTime === null){
        alert("复制课表,必须指定启用结束时间")
        return
      }
      this.copyCourseArrangeModel.id = this.selectedRowKeys[0];//复制课表的id
      //如果复制时不指定教室，则赋值null,后台不进行教室新值插入操作
      if (this.copyClassroomIndex === "0"){
        this.copyCourseArrangeModel.classroomId = null;
      }
      let params = {
        //复制课表，自定义赋值(//id，//课表名称,//课表学期//课表学年//课表班级//班级教室//课表启用开始时间//课表启用结束时间)
        couCourseArrangeAtom : JSON.stringify(this.copyCourseArrangeModel),
      }
      postAction(this.url.copyCourseArrange,params).then((res) => {
        if (res.success){
          this.$message.success(res.message)
          this.copyCourseArrangeVisible = false;//完成后，关闭对话框
        }else {
          this.$message.error(res.message)
        }
      });
    },
    //查询条件联级变动
    changeGradeId() {
      if (this.queryParam.gradeId) { //判断不为空
        this.queryParamSelect.classIdSelect = 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code in(\'' + this.queryParam.gradeId.replaceAll(',','\'!!\'') + '\') order by  class_order'
      }
    },
    selectChangeGradeId(){
      this.copyCourseArrangeDictSelect.classIdSclect = "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 and cc.grade_code = \'"+this.copyCourseArrangeModel.gradeId+"\' order by cc.grade_code !! cc.class_order !! cc.create_time";
    },
    selectChangeBuildingId(){
      this.copyCourseArrangeDictSelect.classroomIdSclect = "fac_classroom fc,fc.classroom_name,fc.id,fc.classroom_iz_open  =1 and fc.building_id = \'"+this.copyCourseArrangeModel.buildingId+"\' order by fc.classroom_order !! fc.create_time";
    },


// <a-menu-item key='1' @click='initCourseArrangeAtom'><a-icon type='delete' />初始化课表</a-menu-item>
// <a-menu-item key='1' @click='refashArrangeAtomTeacher'><a-icon type='delete' />刷新任课老师</a-menu-item>
// <a-menu-item key='1' @click='delInitCourseArrangeAtom'><a-icon type='delete' />删除重新初始化</a-menu-item>
//     initCourseArrangeAtom:初始化课表
    initCourseArrangeAtom: function () {
    if(!this.url.initCourseArrangeAtom){
      this.$message.error("请设置url.initCourseArrangeAtom属性!")
      return
    }
    if (this.selectedRowKeys.length <= 0) {
      this.$message.warning('请选择一条记录！');
      return;
    } else {
      var ids = "";
      for (var a = 0; a < this.selectedRowKeys.length; a++) {
        ids += this.selectedRowKeys[a] + ",";
      }
      var that = this;
      this.$confirm({
        title: "确认初始化",
        content: "是否重新初始化课表?",
        onOk: function () {
          that.loading = true;
          postAction(that.url.initCourseArrangeAtom, {ids: ids}).then((res) => {
            if (res.success) {
              //重新计算分页问题
              that.reCalculatePage(that.selectedRowKeys.length)
              that.$message.success(res.message);
              that.loadData();
              that.onClearSelected();
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.loading = false;
          });
        }
      });
    }
  },

    delInitCourseArrangeAtom:function (){
      if(!this.url.delInitCourseArrangeAtom){
        this.$message.error("请设置url.delInitCourseArrangeAtom属性!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认删除后重新初始化",
          content: "是否删除课表再重新初始化课表?",
          onOk: function () {
            that.loading = true;
            postAction(that.url.delInitCourseArrangeAtom, {ids: ids}).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },
    //refashArrangeAtomTeacher刷新老师
    refashArrangeAtomTeacher: function () {
      if(!this.url.refashArrangeAtomTeacher){
        this.$message.error("请设置url.refashArrangeAtomTeacher!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认初始化",
          content: "是否重新初始化课表?",
          onOk: function () {
            that.loading = true;
            postAction(that.url.refashArrangeAtomTeacher, {ids: ids}).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },//refashArrangeAtomTeacher刷新教室
    refashArrangeAtomClassroom: function () {
      if(!this.url.refashArrangeAtomTeacher){
        this.$message.error("请设置url.refashArrangeAtomClassroom!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认初始化",
          content: "是否重新初始化课表?",
          onOk: function () {
            that.loading = true;
            postAction(that.url.refashArrangeAtomClassroom, {ids: ids}).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },

    //批量启用
    batchizOpen1(){

      if(!this.url.izOpen1Batch){
        this.$message.error("请设置url.izOpen1Batch属性!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认启用",
          content: "是否启用选中数据?",
          onOk: function () {
            that.loading = true;
            deleteAction(that.url.izOpen1Batch, {ids: ids}).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }

    },
    //批量停用
    batchizOpen0(){
      if(!this.url.izOpen0Batch){
        this.$message.error("请设置url.izOpen0Batch属性!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认停用",
          content: "是否停用选中数据?",
          onOk: function () {
            that.loading = true;
            deleteAction(that.url.izOpen0Batch, {ids: ids}).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    }


  }

}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>